package cn.edu.swufe.surverpark.model;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

/**
 *@author 陈龙 E-mail:529914446@qq.com
 *@version创建时间:2015年5月6日下午11:44:55
 *类说明
 */
public abstract class BaseEntity implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 5736441330146788738L;

	public abstract Integer getId();

	public abstract void setId(Integer id);
	
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		try {
			StringBuffer buffer = new StringBuffer();
			Class clazz = this.getClass();
			String simpleName = clazz.getSimpleName();
			buffer.append(simpleName);
			buffer.append("{");
			Field[] fs = clazz.getDeclaredFields();
			Class ftype = null;
			String fname = null;
			Object fvalue = null;
			for(Field f:fs){
				ftype = f.getType();
				fname = f.getName();
				f.setAccessible(true);
				fvalue = f.get(this);
				
				if((ftype.isPrimitive()
						||ftype == Integer.class
						||ftype == Long.class
						||ftype == Short.class
						||ftype == Boolean.class
						||ftype == Character.class
						||ftype == Double.class
						||ftype == Float.class
						||ftype == String.class
						)&&
						!Modifier.isStatic(f.getModifiers())
						){
					buffer.append(fname);
					buffer.append(":");
					buffer.append(fvalue);
					buffer.append(",");
				}
					
			}
			buffer.append("}");
			return buffer.toString();
		} catch (Exception ex) {
			// TODO: handle exception
		}
		return null;
	}
	
}

